home *** CD-ROM | disk | FTP | other *** search
/ s-gikan2.maizuru-ct.ac.jp / s-gikan2.maizuru-ct.ac.jp.zip / s-gikan2.maizuru-ct.ac.jp / pub / old / ncvc350_install.exe / {app} / scripts / decycle_G82.pl < prev    next >
Perl Script  |  2004-04-01  |  5KB  |  190 lines

  1. #! /usr/bin/perl
  2.  
  3. #  G82é≡æ╝é╠NCâRü[âhé╔ò╧è╖é╖éΘâXâNâèâvâg  #
  4.  
  5. $pre_file= $ARGV[0];
  6. $out_file= $ARGV[1];
  7. open(IN,$pre_file);
  8. open(OUT,">$out_file");
  9.  
  10. $initZ= 0;
  11. $kotei_flag= 0;
  12. $G82_flag= 0;
  13. $i= 0;        # âRâüâôâgùpò╧Éö
  14. $G98G99= "G98";
  15.  
  16. while(<IN>){
  17.     if(!/^N?[0-9\s]*[\(\%]/){
  18.         if(/G92/){
  19.             if(/Z([\-\d\.]+)/){ $absoZ= $1; }
  20.         }
  21.         if(/G90/ or /G91/){ $G90G91= $&; }
  22.         if(/G98/ or /G99/){ $G98G99= $&; }
  23.         if($kotei_flag == 1){
  24.             $kotei_flag= koteiCycle_cancel($_);
  25.             if($kotei_flag == 0){ $absoZ= $initZ; }
  26.         }
  27.         else{ $kotei_flag= koteiCycle_start($_); }
  28.         if($G82_flag == 1){ $G82_flag= G82_cancel($_); }
  29.  
  30.         $initZ= $absoZ;
  31.  
  32.         if(/G82/){
  33.             $G82_flag= 1;
  34.  
  35.             if(/[KL]([\d]+)/){ $kurikaeshi_suu= $1; }
  36.             else{ $kurikaeshi_suu= 1; }
  37.             if(/G90/ or /G91/){ print OUT $&."\n"; }
  38.             if(/G98/ or /G99/){ print OUT $&."\n"; }
  39.             while(/[SM][\d\.]+/g){ print OUT $&."\n"; }
  40.  
  41.             @G82cycle= ();
  42.             ($XY_move,$Z_move)= ("","");
  43.  
  44.             ### 1 XüCYì└òWæüæùéΦô«ì∞
  45.             if(/[XY]/){
  46.                 $XY_move= "G00";
  47.                 while(/[XY][\-\d\.]+/g){ $XY_move= $XY_move.$&; }
  48.                 $XY_move= $XY_move."\n";
  49.             }
  50.             ### 2 Rô_É┌ï▀ô«ì∞
  51.             if(/R([\-\d\.]+)/){
  52.                 $R= $1;     #Rô_ò£ïAùpò╧Éö
  53.                 $Z_move= "G00Z".$R."\n";
  54.             }
  55.             else{ undef($R); }
  56.             ### 3 îèèJé»ô«ì∞
  57.             if(/Z([\-\d\.]+)/){
  58.                 $kirikomiZ= $1;     #É╪éΦì₧é▌É[é│ùpò╧Éö
  59.                 if(/F[\d\.]+/){ push(@G82cycle,"G01Z".$kirikomiZ.$&."\n"); }
  60.                 else{ push(@G82cycle,"G01Z".$kirikomiZ."\n"); }
  61.             }
  62.             ### 4 âhâEâFâïô«ì∞
  63.             if(/P[\d\.]+/){    push(@G82cycle,"G04".$&."\n"); }
  64.             ### éT Zì└òWò£ïAô«ì∞
  65.             ## G90é╠é╞é½
  66.             ## G98é╚éτâCâjâVâââïô_é╔üAG99é╚éτRô_é╔û▀éΘ
  67.             if($G90G91 eq "G90"){
  68.                 if($G98G99 eq "G98"){ push(@G82cycle,"G00Z".$initZ."\n"); }
  69.                 else{
  70.                     push(@G82cycle,"G00Z".$R."\n");
  71.                     $initZ= $R;
  72.                 }
  73.             }
  74.             ## G91é╠é╞é½
  75.             ## æOƱé╞é╡é─$RüA$kirikomiZé═â}âCâiâXé╠ÆlüB2,3é╠ìsÆ÷é┼èiö[ì╧é▌
  76.             ## G99é╠é╞é½é═Rô_é╔û▀éΘé╠é┼üAÉ╪éΦì₧é±é╛Zé╠ê┌ô«ù╩é╛é»ÅπÅ╕é╖éΩé╬éµéó
  77.             ## G98é╠é╞é½é═âCâjâVâââïô_é╔û▀éΘé╠é┼üAÉ╪éΦì₧é±é╛Zé╠ê┌ô«ù╩é╞üA
  78.             ## Rô_é¬éáé┴é╜ÅΩìçé═üARô_é▄é┼é╠ê┌ô«ù╩é╛é»é│éτé╔ÅπÅ╕
  79.             else{
  80.                 $kirikomiZ =~ s/-//;
  81.                 ## G98é╠é╞é½é═âCâjâVâââïô_é▄é┼ÅπÅ╕
  82.                 if($G98G99 eq "G98"){
  83.                     if(/R/){
  84.                         if($R =~ /-/){ $return_R= $'; }
  85.                         $kirikomiZ= marume($kirikomiZ,$return_R);
  86.                     }
  87.                     push(@G82cycle,"G00Z".$kirikomiZ."\n");
  88.                 }
  89.                 ## G99é╠é╞é½é═É╪éΦì₧é±é╛ò¬é╛é»ÅπÅ╕üARô_é≡ïLë»
  90.                 else{
  91.                     push(@G82cycle,"G00Z".$kirikomiZ."\n");
  92.                     if(/R/){ $initZ= marume($initZ, $R); }
  93.                 }
  94.             }
  95.  
  96.             for($j=1;$j<=$kurikaeshi_suu;$j++){
  97.                 $i++;
  98.                 print OUT "(Drilling Cycle $i)\n";
  99.                 print OUT $XY_move;
  100.                 if($j == 1){ print OUT $Z_move; }
  101.                 elsif($G98G99 eq "G98" and defined($R)){ print OUT "G00Z".$R."\n"; }
  102.                 foreach (@G82cycle){
  103.                     print OUT;
  104.                 }
  105.             }
  106.         }
  107.  
  108.         else{
  109.             if($G82_flag == 1 and /[XY][\d\-\.\s]+/){
  110.                 $XY_move= "";
  111.                 while(/[XY][\d\.\-]+/g){
  112.                     $XY_move= $XY_move.$&;
  113.                     $_= $`.$';
  114.                 }
  115.                 if(!/[N\d\s]/){    print OUT;}
  116.                 $i++;
  117.                 print OUT "(Drilling Cycle $i)\n";
  118.                 print OUT "G00".$XY_move."\n";
  119.                 if($G98G99 eq "G98" and defined($R)){ print OUT "G00Z".$R."\n"; }
  120.                 foreach (@G82cycle){
  121.                     print OUT;
  122.                 }
  123.             }
  124.             else{
  125.                 ## G82âéü[âhé┼é╚éóÅΩìçüAé╗é╠é▄é▄Åoù═
  126.                 print OUT;
  127.                 ### âCâjâVâââïô_ïLë»ùpé╠Åêù¥
  128.                 ## G90é╠é╞é½
  129.                 if($G90G91 eq "G90"){
  130.                     ## G99é╠é╞é½é═Rô_é╔û▀éΘ
  131.                     if($G98G99 eq "G99"){
  132.                         if(/R([\-\d\.]+)/){ $initZ= $1; }
  133.                     }
  134.                     ## G98é¬éáéΘé╞é½é╠Zé╠ăé╠ÉöÄÜé═É╪éΦì₧é▌é╠É[é│é┼éáé┴é─üAò£ïAé╖éΘì└òWé┼é═é╚éó
  135.                     ## G98é┼é═âCâjâVâââïô_üAé┬é▄éΦé╗éΩê╚æOé╔ê┌ô«é╡é╜Zì└òWé╔ò£ïAé╖éΘé╠é┼$initZé≡ò╧ìXé╖éΘòKùvé═é╚éó
  136.                     ## éµé┴é─üAé╗éΩê╚èOé╠Ä₧é╠Zé╠ê┌ô«ì└òWé≡è─Äïé╖éΘ
  137.                     else{
  138.                         if(/Z([\-\d\.]+)/){ $initZ= $1; }
  139.                     }
  140.                 }
  141.                 ## G91é╠é╞é½é═é╗é╠ôsôxé╠æèæ╬ù╩é┼æ╬Åêé┼é½éΘé¬üAôrÆåé┼G91é⌐éτG90é╔ê┌ìsé╡é╜ÅΩìçüAÉΓæ╬ì└òWé¬ò¬é⌐éτé╚é¡é╚éΘüB
  142.                 ## é╗é▒é┼üAZé╠ÉΓæ╬ì└òWé≡ê┌ô«é╠æèæ╬ù╩é┼öcê¼é╡é─é¿é¡òKùvé¬éáéΘ
  143.                 else{
  144.                     if($G98G99 eq "G99"){
  145.                         if(/R([^A-Z\s]+)/){ $initZ= marume($initZ, $1); }
  146.                     }
  147.                     else{
  148.                         if(/Z([^A-Z\s]+)/){ $initZ= marume($initZ, $1); }
  149.                     }
  150.                 }
  151.             }
  152.         }
  153.     }
  154.     else{ print OUT; }
  155. }
  156.  
  157. close(OUT);
  158. close(IN);
  159.  
  160. sub marume{
  161.     my ($num1,$num2,$enzanshi) = @_;
  162.     my $num;
  163.     $num1 *= 1000;
  164.     $num2 *= 1000;
  165.     $num1= int($num1);
  166.     $num2= int($num2);
  167.     if($enzanshi eq '-'){ $num= ($num1 - $num2) / 1000; }
  168.     else{ $num= ($num1 + $num2) / 1000; }
  169.     if($num !~ /\./ and $num != 0){ $num= $num."\."; }
  170.     return $num;
  171.  
  172. sub koteiCycle_start{
  173.     ($_)= @_;
  174.     if(/G7[346]/ or /G8[1-9]/){ return 1; }
  175.     else{ return 0; }
  176. }
  177.  
  178. sub koteiCycle_cancel{
  179.     ($_)= @_;
  180.     if(/G80/ or /G0*[0123][A-Z\s]/ or /G33/){ return 0; }
  181.     else{ return 1;}
  182. }
  183.  
  184. sub G82_cancel{
  185.     ($_)= @_;
  186.     if(/G7[346]/ or /G8[013-9]/ or /G0*[0123][A-Z\s]/ or /G33/){ return 0; }
  187.     else{ return 1; }
  188. }
  189.